<?php

namespace Biz\service\advertisement\apiModule;

use Doraemon\tools\BlockType;
use Doraemon\tools\ImgUrl;

class HomeFollowCard extends BaseModule
{
    const FORMAT_HIT = 'formatPosHit';

    public function format($hit, $uid, $userProfileExt, $statSignExt)
    {
        $response = [];

        if ($hit) {
            $response = array_map(function ($hit) {
                $index = intval($hit['pos']);
                $id = intval($hit['id']);
                return [
                    'type' => BlockType::TYPE_BANNER,
                    'banner' => [
                        'id' => $id,
                        'index' => $index,
                        'link' => $this->generateLink($hit['link_type'], $hit['link_params']),
                        'banner' => empty($hit['pic_id']) ? '' : ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $hit['pic_id'], ImgUrl::IMAGE_SIZE_OP_ORI),
                        'statType' => (string)'banner' . BlockType::TYPE_CAROUSEL_BANNER . '-' . \Doraemon\model\AdmCarouselBanner::SHOW_TYPE_DYNAMIC,
                        'statSign' => $this->statSign($hit),
                    ],
                    'index' => $index,
                ];
            }, $hit);
            $response = array_values($response);
        }

        return $response;
    }

    public function uniquePos($v): string
    {
        return $v['pos'];
    }

}